package org.dromara.Nyt7PremiumSubsidyInfo.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.Nyt7PremiumSubsidyInfo.domain.vo.Nyt7PremiumSubsidyInfoVo;
import org.dromara.Nyt7PremiumSubsidyInfo.domain.bo.Nyt7PremiumSubsidyInfoBo;
import org.dromara.Nyt7PremiumSubsidyInfo.service.INyt7PremiumSubsidyInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 保费补贴比例
 *
 * @author Lion Li
 * @date 2024-12-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Nyt7PremiumSubsidyInfo/Nyt7PremiumSubsidyInfo")
public class Nyt7PremiumSubsidyInfoController extends BaseController {

    private final INyt7PremiumSubsidyInfoService nyt7PremiumSubsidyInfoService;

    /**
     * 查询保费补贴比例列表
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:list")
    @GetMapping("/list")
    public TableDataInfo<Nyt7PremiumSubsidyInfoVo> list(Nyt7PremiumSubsidyInfoBo bo, PageQuery pageQuery) {
        return nyt7PremiumSubsidyInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出保费补贴比例列表
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:export")
    @Log(title = "保费补贴比例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Nyt7PremiumSubsidyInfoBo bo, HttpServletResponse response) {
        List<Nyt7PremiumSubsidyInfoVo> list = nyt7PremiumSubsidyInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "保费补贴比例", Nyt7PremiumSubsidyInfoVo.class, response);
    }

    /**
     * 获取保费补贴比例详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:query")
    @GetMapping("/{id}")
    public R<Nyt7PremiumSubsidyInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(nyt7PremiumSubsidyInfoService.queryById(id));
    }

    /**
     * 新增保费补贴比例
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:add")
    @Log(title = "保费补贴比例", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Nyt7PremiumSubsidyInfoBo bo) {
        return toAjax(nyt7PremiumSubsidyInfoService.insertByBo(bo));
    }

    /**
     * 修改保费补贴比例
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:edit")
    @Log(title = "保费补贴比例", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Nyt7PremiumSubsidyInfoBo bo) {
        return toAjax(nyt7PremiumSubsidyInfoService.updateByBo(bo));
    }

    /**
     * 删除保费补贴比例
     *
     * @param ids 主键串
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:remove")
    @Log(title = "保费补贴比例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(nyt7PremiumSubsidyInfoService.deleteWithValidByIds(List.of(ids), true));
    }




    /**
     * 导出选中的保费补贴比例列表
     */
    @SaCheckPermission("Nyt7PremiumSubsidyInfo:Nyt7PremiumSubsidyInfo:export")
    @Log(title = "保费补贴比例", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelected")
    public void exportSelected(@RequestBody List<Long> ids, HttpServletResponse response) {
        List<Nyt7PremiumSubsidyInfoVo> list = nyt7PremiumSubsidyInfoService.queryListByIds(ids);
        ExcelUtil.exportExcel(list, "保费补贴比例", Nyt7PremiumSubsidyInfoVo.class, response);
    }


}
